<?php
!defined('P_W') && exit('Forbidden');
InitGP(array('act'));
$action = $act;
if (empty($action)) {
	require_once(R_P.'require/credit.php');
	include_once(D_P . 'data/bbscache/house_config.php');
	ifcheck($house_evaluation_open,'house_evaluation_open');
	ifcheck($house_evaluation_check,'house_evaluation_check');
	$house_mapsearch_a = $house_mapsearch_b = $house_mapsearch_c = '';
	if ($house_mapsearch == '5') {
		$house_mapsearch_a = 'checked';
	} elseif ($house_mapsearch == '10') {
		$house_mapsearch_b = 'checked';
	} elseif ($house_mapsearch == '15') {
		$house_mapsearch_c = 'checked';
	}
	
	//二手房新增功能
	ifcheck($house_topifopen,'house_topifopen');
	ifcheck($house_rapidifopen,'house_rapidifopen');
	ifcheck($house_defaultindex,'house_defaultindex');
	$style = ($house_newhouseifopen && $house_secondhouseifopen) ? '' : 'none';
	$house_newhouseifopenCheck = $house_newhouseifopen ? 'CHECKED' : '';
	$house_secondhouseifopenCheck = $house_secondhouseifopen ? 'CHECKED' : '';
	
	$topHireCreditList = '';
	foreach ($credit->cType as $key => $value) {
		$topHireCreditList.= "<option value=\"$key\"".($house_hire_topcredit==$key ? ' selected' : '').">$value</option>";
	}
	
	$topSaleCreditList = '';
	foreach ($credit->cType as $key => $value) {
		$topSaleCreditList.= "<option value=\"$key\"".($house_sale_topcredit==$key ? ' selected' : '').">$value</option>";
	}
	
	$rapidSaleCreditList = '';
	foreach ($credit->cType as $key => $value) {
		$rapidSaleCreditList.= "<option value=\"$key\"".($house_sale_rapidcredit==$key ? ' selected' : '').">$value</option>";
	}
	
	$rapidHireCreditList = '';
	foreach ($credit->cType as $key => $value) {
		$rapidHireCreditList.= "<option value=\"$key\"".($house_hire_rapidcredit==$key ? ' selected' : '').">$value</option>";
	}
	
	$action = $_COOKIE['admin_house_basic'];
	!$action && $action = 'core';
	
} elseif ($action == 'edit') {

	InitGP(array('config','tagname','tagurl'), 'GP');
	empty($config) && adminmsg('非法操作');
	$hottag = array();
	foreach ($tagname as $key => $value) {
		if ($value && $tagurl[$key]) {
			$hottag[] = array('name' => $value, 'url' => $tagurl[$key]);
		}
	}
	$filterFields = array(
				'house_topprice', 
				'house_rapidprice',
				'house_hire_expried',
				'house_sale_expried',
				'house_sale_topprice',
				'house_sale_num',
				'house_hire_topprice',
				'house_hire_num',
				'house_sale_rapidprice',
				'house_hire_rapidprice'
			);
	foreach ($config as $key => $value) {
		if (!in_array($key, $filterFields)) continue;
		$config[$key] = (int) $value;
	}
	$config['house_newhouseifopen'] = (int) $config['house_newhouseifopen'];
	$config['house_secondhouseifopen'] = (int) $config['house_secondhouseifopen'];
	$config['house_hottag'] = $hottag;
	if($config['house_hire_expried'] <= 0 || $config['house_sale_expried'] <= 0){
		adminmsg('出租或出售房源的有效期必须为大于零的正整数');
	}
	
	if(!$config['house_newhouseifopen'] || !$config['house_secondhouseifopen']){
		unset($config['house_defaultindex']);
	}
	foreach ($config as $key => $value) {
		setConfig($key, $value, null, true);
	}
	updatecache_conf('house', true);
	adminmsg('operate_success');
}
include PrintMode('global');
exit;
?>